package xyz.scootaloo.oj.leetcode

import org.junit.Test
import xyz.scootaloo.common.TestDsl

/**
 * @author flutterdash@qq.com
 * @since 2021/7/2 16:25
 */
class P509 : TestDsl {

    private fun fib(n: Int): Int {
        when (n) {
            0 -> return 0
            1, 2 -> return 1
        }
        val dp = intArrayOf(1, 1)
        var sum: Int
        for (i in 2 until n) {
            sum = dp[0] + dp[1]
            dp[0] = dp[1]
            dp[1] = sum
        }
        return dp[1]
    }

    @Test
    fun test0() {
        fib(0) shouldBe 0
        fib(1) shouldBe 1
        fib(2) shouldBe 1
        fib(3) shouldBe 2
        fib(4) shouldBe 3
    }

}
